//package com.dxjy.admin.config;
//
//import org.springframework.boot.web.servlet.FilterRegistrationBean;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.Ordered;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
//import org.springframework.web.filter.CorsFilter;
//
///**
// * @Author: zhang
// * @Date: 2019/3/29 13:41
// * @Description: 全局CORS跨域配置
// */
//
//@Configuration
//public class CORSConfiguration {
//
//    //    @Bean
////    public WebMvcConfigurer corsConfigurer() {
////        return new WebMvcConfigurerAdapter() {
////            @Override
////            public void addCorsMappings(CorsRegistry registry) {
//////				registry.addMapping("/api/**");
////                registry.addMapping("/**")
////                        .allowedOrigins("http://192.168.160.128",
////                                        "http://127.0.0.1:8848",
////                                        "http://127.0.0.1:5500",
////                                        "http://127.0.0.1:8080",
////                                        "http://localhost:8080",
////                                        "http://172.16.1.70:8080")
////                        .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
////                        .allowCredentials(false).maxAge(3600);
////            }
////        };
////    }
//
//    private CorsConfiguration buildConfig() {
//        CorsConfiguration corsConfiguration = new CorsConfiguration();
//        // 1
//        corsConfiguration.addAllowedOrigin("*");
//        // 2
//        corsConfiguration.addAllowedHeader("*");
//        // 3
//        corsConfiguration.addAllowedMethod("*");
//        corsConfiguration.setAllowCredentials(true);
//        return corsConfiguration;
//    }
//
//    @Bean
//    public FilterRegistrationBean corsFilter() {
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        // step 4
//        source.registerCorsConfiguration("/**", buildConfig());
//        FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
//        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
//        return bean;
//    }
//
//}
